﻿#ifndef CCAMERACONNECTBASLER_H
#define CCAMERACONNECTBASLER_H

#include <pylon/PylonIncludes.h>
#include <pylon/gige/BaslerGigECamera.h>
#include<iostream>
#include <pylon/gige/BaslerGigEInstantCamera.h>
#include "HalconCpp.h"
#include <QTimer>
#include <QImage>

typedef Pylon::CBaslerGigEInstantCamera Camera_t;
typedef Camera_t::GrabResultPtr_t GrabResultPtr_t;
using namespace Pylon;
using namespace GenApi;
using namespace Halcon;
//巴斯勒相机类
class CcameraConnectBasler
{
public:
    CcameraConnectBasler(QString cameraName);
    ~CcameraConnectBasler();
public:
    bool findCamera();                           //寻找m_cameraName相机，并将指针传递至m_pCamera
    bool connect();                              //连接cameraName相机
    bool disConnect();                           //关闭cameraName相机
    bool isConnected();                          //判断是否连接
    bool setSoftTrigger();                       //设置软触发
    bool setExposureTime(double exposureTime);   //设置曝光时间
    bool setGainRaw(double gain);                //设置增益
    bool getExposureTime(double *expTime);        //获取当前曝光时间（16μs-1000000μm）
    bool getGainRaw(double *gain);                //获取当前增益值(1-32)

    bool getOneFrame(Hobject* image);                //获取一张图片
    bool grabOneFrame(Hobject* image);
    bool openGrabFrame();
    bool stopGrabFrame();
    Hobject QImageToHobject(QImage *input,int Type);

private:
    bool GetIntPara(const char * nameNode, int64_t&  para);
    bool SetIntPara(const char * nameNode, INT64 para);
    int64_t Adjust(int64_t val, int64_t minimum, int64_t maximum, int64_t inc);

private:
    QString m_cameraName;
    INodeMap* m_nodeMap;
    HTuple m_WindowHandle1;
    Pylon::CDeviceInfo m_deviceInfo;
    Camera_t* m_camera;// 相机指针
    Pylon::DeviceInfoList_t m_devList;           //相机信息参数表
    IPylonDevice* m_a ;
    QStringList m_nameList;
    QVector<quint8> m_buffer;                     //图片buffer
    INT64  width;
    INT64  height;
};

#endif // CCAMERACONNECTBASLER_H
